package com.drcoffee.drcoffeemall.controller;


import com.drcoffee.drcoffeemall.entry.Address;
import com.drcoffee.drcoffeemall.entry.Result;
import com.drcoffee.drcoffeemall.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 收件地址
 *
 * @author ShiHao Zhou
 */
@RequestMapping("/address")
@RestController
public class AddressController {
    @Autowired
    AddressService addAddress;
    /*
     * 添加地址
     * */
    @PostMapping("/addAddress")
    public Result addAddress(@RequestHeader String Token, @RequestBody Address address) {
        return addAddress.addAddress(Token,address);
    }

    /*
     * 查询地址
     * */
    @GetMapping("/getAddressByAccount")
    public Result getAddressByAccount(@RequestParam String account) {
        return addAddress.getAddressByAccount(account);
    }

    /*
     * 根据Id查询地址
     * */
    @GetMapping("/getAddressById")
    public Result getAddressById(@RequestParam Integer id) {
        return addAddress.getAddressById(id);
    }

    /*
     * 删除地址
     * */
    @GetMapping("/deleteAddress")
    public Result deleteAddress(@RequestParam Integer id, @RequestParam String account) {
        return addAddress.deleteAddress(id, account);
    }

    /*
     * 修改地址
     * */
    @PostMapping("/updateAddress")
    public Result updateAddress(@RequestBody Address address) {
        return addAddress.updateAddress(address);
    }

    /**
     * 自动识别
     */
    @GetMapping("/autoAddress")
    public Result autoAddress(@RequestParam String autoText) {
//        Address as = addAddress.autoAddress(autoText);
//        System.out.println(as);
        return addAddress.autoAddress(autoText);
    }

}
